package com.qbw.app.manager;

import com.qbw.actionmanager.ActionManager;
import com.qbw.app.Constant;
import com.qbw.app.action.MapChangedAction;
import com.qbw.spm.P;

/**
 * @author QBW
 * @date 2019/10/14
 */
public class MapManager {

    private static MapManager sInstance;
    private boolean mUseBaidu;

    private MapManager() {
        mUseBaidu = isBaidu();
    }

    public static MapManager getInstance() {
        if (sInstance == null) {
            synchronized (MapManager.class) {
                if (sInstance == null) {
                    sInstance = new MapManager();
                }
            }
        }
        return sInstance;
    }

    public void setMap(boolean isBaidu) {
        mUseBaidu = isBaidu;
        P.putString(Constant.KEY_MAP, isBaidu ? Constant.MAP_BAIDU : Constant.MAP_GOOGLE);
        ActionManager.getInstance().triggerAction(new MapChangedAction());
    }

    private boolean isBaidu() {
        return Constant.MAP_BAIDU.equals(P.getString(Constant.KEY_MAP, Constant.MAP_DEFAULT));
    }

    public boolean isUseBaidu() {
        return mUseBaidu;
    }
}
